/* This program is distributed under the GPL, version 2 */

#include <stdio.h>
#include <unistd.h>
#include <octopus.h>

int main(int argc, char **argv)
{
#if 0
    struct octopus_context octopusc;
    int f,i;
    char buf[1];

    octopus_init(&octopusc);

    f = octopus_usb_open(&octopusc, 0x0403, 0x6001);

    if(f < 0 && f != -5) {
        fprintf(stderr, "unable to open octopus device: %d (%s)\n", f, octopus_get_error_string(&octopusc));
        exit(-1);
    }

    printf("octopus open succeeded: %d\n",f);

    printf("enabling bitbang mode\n");
    octopus_enable_bitbang(&octopusc, 0xFF);

    sleep(3);

    buf[0] = 0x0;
    printf("turning everything on\n");
    f = octopus_write_data(&octopusc, buf, 1);
    if(f < 0) {
        fprintf(stderr,"write failed for 0x%x, error %d (%s)\n",buf[0],f, octopus_get_error_string(&octopusc));
    }

    sleep(3);

    buf[0] = 0xFF;
    printf("turning everything off\n");
    f = octopus_write_data(&octopusc, buf, 1);
    if(f < 0) {
        fprintf(stderr,"write failed for 0x%x, error %d (%s)\n",buf[0],f, octopus_get_error_string(&octopusc));
    }

    sleep(3);

    for(i = 0; i < 32; i++) {
        buf[0] =  0 | (0xFF ^ 1 << (i % 8));
        if( i > 0 && (i % 8) == 0) {
            printf("\n");
        }
        printf("%02hhx ",buf[0]);
        fflush(stdout);
        f = octopus_write_data(&octopusc, buf, 1);
        if(f < 0) {
            fprintf(stderr,"write failed for 0x%x, error %d (%s)\n",buf[0],f, octopus_get_error_string(&octopusc));
        }
        sleep(1);
    }

    printf("\n");

    printf("disabling bitbang mode\n");
    octopus_disable_bitbang(&octopusc);

    octopus_usb_close(&octopusc);
    octopus_deinit(&octopusc);
  #endif
}
